import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import { spaceid } from './config';
import p001 from './p001';
import p002 from './p002';
export default async function a002(fd: IFeidaoAiBrowserComponent, args: { moid: string, currentTarget: HTMLElement, compen: string, event: string, tabname: string }) {
	//  调用事件
	fd.data.node.classList.remove('display-n');
	const data = args;

	set(fd, 'compen', data.compen);
	set(fd, 'event', data.event);
	set(fd, 'tabname', data.tabname);

	const tabname = data.tabname;
	set(fd, 'productid', spaceid);

	const query = {
		filter: {
			tablename: tabname,
			productid: spaceid
		}
	};
	// const res = await nodejs<{ count: number; dataArray: object[]; page_size: number; page_no: number }>(url, './permissions/role_type_find2', query, false, false);
	// debugger;
	const res = await nodejs<{
		dataArray: Array<{
			file_cont: string
		}>
	}>('role-type/zj-000010/s001', query);
	let obj = {} as {
		fields: {
			dataArray: object[]
		}
	};
	res.dataArray.forEach((v) => {
		obj = JSON.parse(v.file_cont);
	});
	// console.log(res, '--');
	const p2 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
	const p1 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p001"]');
	if (res.dataArray.length === 0) {
		p1.classList.add('display-n');
		p2.classList.remove('display-n');
		render(fd, '', p001, 'p001', 'inner');
		render(fd, '', p002, 'p002', 'inner');
	} else {
		p2.classList.add('display-n');
		p1.classList.remove('display-n');
		render(fd, obj.fields.dataArray, p001, 'p001', 'inner');
	}
}
